package pl.ptemich.bumbastic;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Polygon;



public abstract class AbstractHex implements Hex {
    
    boolean selected = false;
    
    //position in the table of Hex objects
    protected int hexX;
    
    //position in the table of Hex objects
    protected int hexY;
    
    protected Point center;
    
    protected int side;
    
    protected Point[] vertexes;

    public static double calculateH(int side) {
        return Math.sin(Math.toRadians(30)) * side;
    }
    
    public static double calculateR(int side) {
        return Math.cos(Math.toRadians(30)) * side;
    }    

    
    public void draw(Graphics g) {
        if (selected) {
            Polygon poly = new Polygon();
            poly.addPoint(vertexes[0].getPosX(), vertexes[0].getPosY());
            poly.addPoint(vertexes[1].getPosX(), vertexes[1].getPosY());
            poly.addPoint(vertexes[2].getPosX(), vertexes[2].getPosY());
            poly.addPoint(vertexes[3].getPosX(), vertexes[3].getPosY());
            poly.addPoint(vertexes[4].getPosX(), vertexes[4].getPosY());
            poly.addPoint(vertexes[5].getPosX(), vertexes[5].getPosY());            
            g.fill(poly);
        } 
        
        //g.setColor(new Color(179, 255, 38));
        g.setLineWidth(1);
        g.drawLine(vertexes[0].getPosX(), vertexes[0].getPosY(), vertexes[1].getPosX(), vertexes[1].getPosY());
        g.drawLine(vertexes[1].getPosX(), vertexes[1].getPosY(), vertexes[2].getPosX(), vertexes[2].getPosY());
        g.drawLine(vertexes[2].getPosX(), vertexes[2].getPosY(), vertexes[3].getPosX(), vertexes[3].getPosY());
        g.drawLine(vertexes[3].getPosX(), vertexes[3].getPosY(), vertexes[4].getPosX(), vertexes[4].getPosY());
        g.drawLine(vertexes[4].getPosX(), vertexes[4].getPosY(), vertexes[5].getPosX(), vertexes[5].getPosY());
        g.drawLine(vertexes[5].getPosX(), vertexes[5].getPosY(), vertexes[0].getPosX(), vertexes[0].getPosY());
        

        //g.drawString(hexX + ":" + hexY, vertexes[0].getPosX(), vertexes[0].getPosY());                
    }
}
